package com.silence.gmall.product.assembler;

import com.silence.gmall.product.domain.entity.SpuImage;
import com.silence.gmall.product.dto.SpuImageDto;
import org.mapstruct.*;

import java.util.List;

/**
 * @Author silence
 * @Date 2025-08-18 23:11
 * @Email 792245022@qq.com
 * @Version 1.0
 * @Description 商品图片工厂
 */
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
public interface SpuImageFactory {

    /**
     * 将 SpuImage 转换为 SpuImageDto
     *
     * @param source 源对象
     * @return 目标对象
     */
    SpuImageDto spuImage2SpuImageDto(SpuImage source);

    /**
     * 将 SpuImageList 转换为 SpuImageDtoList
     *
     * @param source 源对象
     * @return 目标对象
     */
    List<SpuImageDto> spuImageList2SpuImageDtoList(List<SpuImage> source);

    /**
     * 将 SpuImageDto 转换为 SpuImage
     *
     * @param source 源对象
     * @return 目标对象
     */
    @Named("spuImageDto2SpuImageWithContext")
    @Mapping(target = "spuId", expression = "java(spuId)")
    SpuImage spuImageDto2SpuImageWithContext(SpuImageDto source, @Context Long spuId);

    /**
     * 将 SpuImageDtoList 转换为 SpuImageList
     *
     * @param source 源对象
     * @return 目标对象
     */
    @Named("spuImageDtoList2SpuImageListWithContext")
    @IterableMapping(qualifiedByName = "spuImageDto2SpuImageWithContext")
    List<SpuImage> spuImageDtoList2SpuImageListWithContext(List<SpuImageDto> source, @Context Long spuId);

}
